package com.cwz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cwz.entity.ApiAccessLog;
import com.cwz.entity.Material;
import com.cwz.mapper.ApiAccessLogMapper;
import com.cwz.param.ApiHttpQueryParam;
import com.cwz.service.ApiAccessLogService;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author wenZhen
 * @create 2024-08-18 17:38
 */

@Service
public class ApiAccessLogServiceImpl implements ApiAccessLogService {


    @Resource
    private ApiAccessLogMapper apiAccessLogMapper;
    @Override
    public Map<String, Object> page(ApiHttpQueryParam param, HttpSession session) {
        checkAdminRole(session);
        QueryWrapper queryWrapper=new QueryWrapper();
        IPage<ApiAccessLog> page=new Page<>(param.getCurrent(),param.getSize());

        queryWrapper.like(!StringUtils.isNullOrEmpty(param.getApiName()),"api_name",param.getApiName())
                .eq(param.getClientIp()!=null,"client_ip",param.getClientIp())
                .eq(param.getUsername()!=null,"username",param.getUsername());

        page= apiAccessLogMapper.selectPage(page, queryWrapper);

        return success(page);
    }
}
